// MyVoteDlg.cpp : implementation file
//

#include "stdafx.h"
#include "client.h"
#include "MyVoteDlg.h"

#include "Global.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CMyVoteDlg dialog


CMyVoteDlg::CMyVoteDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CMyVoteDlg::IDD, pParent)
{
	hTimer = NULL;
	NowLeftTime = 15;
	//{{AFX_DATA_INIT(CMyVoteDlg)
	m_BanishReson = _T("");
	m_TargetID = _T("");
	//}}AFX_DATA_INIT
}


void CMyVoteDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CMyVoteDlg)
	DDX_Control(pDX, IDC_PROGRESS, m_TimeProgress);
	DDX_Text(pDX, IDC_EDIT_BANISHRESON, m_BanishReson);
	DDX_Text(pDX, IDC_EDIT_TARGETID, m_TargetID);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CMyVoteDlg, CDialog)
	//{{AFX_MSG_MAP(CMyVoteDlg)
	ON_WM_DESTROY()
	ON_WM_TIMER()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMyVoteDlg message handlers

int CMyVoteDlg::DoModal() 
{
	// TODO: Add your specialized code here and/or call the base class
	
	return CDialog::DoModal();
}

BOOL CMyVoteDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	UpdateData(FALSE);

	hTimer = SetTimer(MYVOTE_TIMER, 1000, NULL);
	NowLeftTime = 15;
	m_TimeProgress.SetRange(0, NowLeftTime);

	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CMyVoteDlg::OnOK() 
{
	// TODO: Add extra validation here
	CSV_MYBANISHVOTE mvmsg;
	mvmsg.Set(TRUE);
	SockMan.SendData(g_MainSrvSID, mvmsg.pData, mvmsg.GetTotalSize());
	CDialog::OnOK();
}

void CMyVoteDlg::OnCancel() 
{
	// TODO: Add extra cleanup here
	CSV_MYBANISHVOTE mvmsg;
	mvmsg.Set(FALSE);
	SockMan.SendData(g_MainSrvSID, mvmsg.pData, mvmsg.GetTotalSize());
	CDialog::OnCancel();
}

void CMyVoteDlg::OnDestroy() 
{
	CDialog::OnDestroy();
	
	// TODO: Add your message handler code here
	if(hTimer) KillTimer(hTimer);
	hTimer = NULL;
}

void CMyVoteDlg::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default
	if(nIDEvent == MYVOTE_TIMER)
	{
		NowLeftTime--;
		m_TimeProgress.SetPos(NowLeftTime);
		if(NowLeftTime<=0)
		{
			OnCancel();
			return;
		}
	}

	CDialog::OnTimer(nIDEvent);
}
